<template>
  <TManageLayout>
    <div class="content-container">
      <h2 class="welcome-text">老师，您好。欢迎使用AIGC智育优学教育平台。</h2>
      <div class="schedule-table">
        <table>
          <colgroup>
            <col />
            <col />
            <col />
            <col />
            <col />
            <col />
            <col />
            <col />
            <col />
          </colgroup>
          <thead>
            <tr>
              <th></th>
              <th></th>
              <th>星期一</th>
              <th>星期二</th>
              <th>星期三</th>
              <th>星期四</th>
              <th>星期五</th>
              <th>星期六</th>
              <th>星期日</th>
            </tr>
          </thead>
          <tbody>
            <!-- 上午 -->
            <tr>
              <td class="time-label" rowspan="2">上午</td>
              <td class="period">第一节</td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
            </tr>
            <tr>
              <td class="period">第二节</td>
              <td></td>
              <td></td>
              <td class="course-cell" @click="goToLessonSchedule('java-001')">Java</td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
            </tr>
            <!-- 下午 -->
            <tr>
              <td class="time-label" rowspan="2">下午</td>
              <td class="period">第三节</td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
            </tr>
            <tr>
              <td class="period">第四节</td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
            </tr>
            <!-- 晚上 -->
            <tr>
              <td class="time-label">晚上</td>
              <td class="period">第五节</td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
  </TManageLayout>
</template>

<script lang="ts" setup>
import { useRouter } from 'vue-router';
import TManageLayout from '@/components/TManageLayout.vue';

const router = useRouter();

// 添加跳转方法
const goToLessonSchedule = (courseManageId) => {
  try {
    router.push({
      path: `/teacher/manager/lessonschedule/${courseManageId}`
    });
  } catch (error) {
    console.error('导航错误：', error);
    // 降级处理
    window.location.href = `/teacher/manager/lessonschedule/${courseManageId}`;
  }
};
</script>

<style scoped>
.content-container {
  padding: 0 20px;
  height: 100%;
  width: 100%;
}

.welcome-text {
  margin: 0 0 20px;
  padding-top: 5px;
  color: #333;
  font-size: 1.2em;
}

.schedule-table {
  width: 100%;
  padding: 20px 0;
  min-width: 800px;
}

table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid #ddd;
  table-layout: fixed;
  min-width: 800px;
}

table colgroup col:nth-child(1) { width: 25px; }
table colgroup col:nth-child(2) { width: 25px; }
table colgroup col:nth-child(n+3) { width: calc((100% - 50px) / 7); }

th, td {
  border: 1px solid #ddd;
  text-align: center;
  position: relative;
  padding: 0;
  height: 100px;
  box-sizing: border-box;
  overflow: hidden;
}

td:not(.time-label):not(.period) {
  position: relative;
}

td:not(.time-label):not(.period) > * {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  text-align: center;
}

tr:not(:first-child) {
  height: 100px;
}

th {
  height: 30px;
  background-color: #f5f7fa;
  color: #606266;
  font-weight: normal;
  vertical-align: middle;
}

.time-label, .period {
  background-color: #f5f7fa;
  font-weight: bold;
  writing-mode: vertical-lr;
  text-orientation: upright;
  width: 25px !important;
  min-width: 25px !important;
  max-width: 25px !important;
  overflow: hidden;
  white-space: nowrap;
  height: 100px;
}

.course-cell {
  background-color: #e6f3ff;
  color: #409EFF;
  font-weight: 500;
  transition: all 0.3s;
  cursor: pointer;
  user-select: none; /* 防止文字被选中 */
}

.course-cell:hover {
  background-color: #d0e7ff;
  transform: scale(1.02); /* 添加轻微的放大效果 */
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1); /* 添加悬浮阴影 */
}

.course-cell:active {
  transform: scale(0.98); /* 点击时的按压效果 */
}

td > div, th > div {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

td:not(.time-label):not(.period):hover {
  background-color: #f0f9ff;
  cursor: pointer;
}

td > * {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 5px;
}

@media screen and (max-width: 800px) {
  .schedule-table {
    overflow-x: auto;
  }
}
</style>
